import { ContentType } from '@/enums/httpEnum';
import { request } from '@umijs/max';
import { downLoadXlsx } from '@/utils/downloadfile';

// 查询故障信息列表
export async function getFaultList(params?: API.Manage.FaultListParams) {
  return request<API.Manage.FaultPageResult>('/api/inspection/faultMain/list', {
    method: 'GET',
    headers: { 'Content-Type': ContentType.FORM_URLENCODED },
    params
  });
}

// 查询故障类型信息列表
export async function getFaultTypes(params?: API.Manage.FaultListParams) {
  return request<API.Manage.FaultPageResult>('/api/inspection/faultType/list', {
    method: 'GET',
    headers: { 'Content-Type': ContentType.FORM_URLENCODED },
    params
  });
}


// 仅查询故障名称列表
export async function getFaultNames() {
  return request<API.Manage.FaultType>('/api/inspection/faultType/allTypeName', {
    method: 'GET',
    headers: { 'Content-Type': ContentType.FORM_URLENCODED },
  });
}

// 根据故障ID获取故障详情
export async function getFaultTypeById(id: number) {
  return request<API.Result>(`/api/inspection/faultType/${id}`, {
    method: 'GET',
    data: id
  });
}

//新增故障
export function addFault(params: API.Manage.Fault) {
  return request<API.Result>('/api/inspection/faultMain/add', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json;charset=UTF-8',
    },
    data: params,
  });
}

//更新故障
export function updateFault(params: API.Manage.Fault) {
    return request<API.Result>('/api/inspection/faultMain/update', {
      method: 'POST',
      headers: {
          'Content-Type': 'application/json;charset=UTF-8',
      },
      data: params,
    });
  }

// 删除故障信息
export async function removeFault(ids: number[]) {
  return request<API.Result>('/api/inspection/faultMain/delete', {
    method: 'POST',
    data: ids
  });
}